<template>
  <div class="form-container">
    <el-form inline :model="form" ref="refForm" class="form-line" label-width="70">
      <el-form-item label="卡券名称" prop="couponName">
        <el-input size="default" v-model="form.couponName" placeholder="卡券名称"></el-input>
      </el-form-item>
    </el-form>
    <div class="btn-container">
      <el-button type="primary" @click="handleReset(refForm as FormInstance)">重置</el-button>
      <el-button type="primary" @click="getList">查询</el-button>
      <el-button type="primary" @click="router.push('/cityLevel/cityMarket/order/add')">卖出</el-button>
    </div>
  </div>
  <div class="table-container">
    <el-table
      border
      :cell-style="{ textAlign: 'center', fontSize: '13px' }"
      :header-cell-style="{
        textAlign: 'center',
        fontWeight: '100',
        fontSize: '13px',
        color: 'white',
        backgroundColor: '#009688'
      }"
      :data="list"
      style="width: 100%"
    >
      <el-table-column prop="couponName" label="卡券名称" />
      <el-table-column prop="couponType" label="卡券类型">
        <template #default="scope">{{ scope.row.couponType == 1 ? "配送券" : "" }}</template>
      </el-table-column>
      <el-table-column prop="couponPrice" label="卡券原价" />
      <el-table-column prop="couponDiscount" label="卡券折扣价" />
      <el-table-column prop="useTimes" label="可使用次数" />
      <el-table-column prop="expire" label="有效时长" />
      <el-table-column prop="platform" label="所属平台" />
      <el-table-column prop="purchaseQuantity" label="购买数量" />
      <el-table-column prop="amount" label="金额" />
    </el-table>
  </div>
</template>

<script lang="tsx" name="CitySiteIndex" setup>
import { MarketOrder } from "@/api/interface/city/cityMarket/order";
import { getOrderDetailAPI } from "@/api/modules/city/cityMarket/order/api";
import { ElMessage, FormInstance } from "element-plus";
import { onMounted, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
const router = useRouter();
const route = useRoute();
let form = ref<MarketOrder.DetailParams>({
  orderCode: ""
});
const refForm = ref<FormInstance>();
const list = ref<MarketOrder.Detail[]>([]);
const handleReset = (ruleForm: FormInstance) => {
  ruleForm.resetFields();
};
const getList = async () => {
  const { code, data, msg } = await getOrderDetailAPI(form.value);
  if (code == "200" && data) {
    list.value = data;
  } else {
    ElMessage.error(msg);
  }
};
onMounted(() => {
  if (route.query.code != undefined) {
    form.value.orderCode = route.query.code as string;
    getList();
  }
});
</script>
<style lang="scss" scoped>
.form-container {
  padding: 10px;
  margin-bottom: 10px;
  background-color: white;
  .btn-container {
    display: inline-block;
    float: right;
    vertical-align: middle;
  }
  .el-form {
    display: inline-block;
  }
  .form-line {
    .el-form-item {
      width: 260px;
      margin: 0;
      margin-right: 10px;
    }
    .el-input {
      width: 240px;
    }
    .el-select {
      width: 240px;
    }
  }
}
.table-container {
  padding: 40px 10px;
  padding-bottom: 60px;
  background-color: white;
  .pagination-container {
    // display: inline-block;
    float: right;
    margin-top: 20px;
    background-color: white;
  }
}
::v-deep .el-form-item__label {
  font-size: 13px;
}
::v-deep .el-button > span {
  font-size: 13px;
}
::v-deep .el-input__inner {
  font-size: 13px;
}
</style>
